// pages/content/content.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    teacherName:"",
    teacherCourse:"",
    teacherId:"",
    teacherEvaluateFlag:"",
    array: ['优秀', '良好', '中等', '及格','不及格'],
    index1:0,
    index2:0,
    index3:0,
    index4:0,
    index5:0,
    index6:0,
    index7:0,
    index8:0,
    index9:0,
    index10:0,
    questionAdvice:""
  },
  goback:function (params) {
    console.log("gobackgobackgobackgoback")
    wx.switchTab({
      url: '/pages/working/working',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.teacherName+options.teacherCourse)
    var teacherName = options.teacherName;
    var teacherCourse = options.teacherCourse;
    var teacherId = options.teacherId;
    var teacherEvaluateFlag = options.teacherEvaluateFlag;
    console.log(teacherName+teacherCourse+" flag:"+teacherEvaluateFlag+"teacherId:"+teacherId)

    var url = app.globalData.url;
    var that = this;

    //如果是已经评教的，抓取评教的信息
    if(teacherEvaluateFlag=="1"){
      wx.request({
        url: url+'/getEvaluateQuestion', 
        data: {
          teacherId: teacherId
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (res) {
          console.log(res.data)
          console.log("属性："+res.data.question1)
          that.setData({
            index1:res.data.question1,
            index2:res.data.question2,
            index3:res.data.question3,
            index4:res.data.question4,
            index5:res.data.question5,
            index6:res.data.question6,
            index7:res.data.question7,
            index8:res.data.question8,
            index9:res.data.question9,
            index10:res.data.question10,
            questionAdvice:res.data.questionAdvice
          })

        }
      })
    }

    this.setData({
      teacherName:teacherName,
      teacherCourse:teacherCourse,
      teacherId:teacherId,
      teacherEvaluateFlag:teacherEvaluateFlag
    })

  },
  keepQuestion:function (params) {
    //保存问题
    var url = app.globalData.url;
    var studentId = app.globalData.studentId;
    var that = this;

    // var result = [that.data.index1,that.data.index2,that.data.index3,that.data.index4,that.data.index5,that.data.index6,that.data.index7,that.data.index8,that.data.index9,that.data.index10]
    // console.log(result)
    var result = new Array();
    result.push(that.data.index1);
    result.push(that.data.index2);
    result.push(that.data.index3);
    result.push(that.data.index4);
    result.push(that.data.index5);
    result.push(that.data.index6);
    result.push(that.data.index7);
    result.push(that.data.index8);
    result.push(that.data.index9);
    result.push(that.data.index10);
    console.log(result)

    wx.request({
      url: url+'/addQuestion', 
      data: {
        studentId:studentId,
        teacherId: that.data.teacherId,
        result:result,
        teacherEvaluateFlag:that.data.teacherEvaluateFlag,
        questionAdvice:that.data.questionAdvice
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log(res.data)
        if(res.data.value=="success"){
          wx.showToast({
            title: '提交成功!',
            icon: 'success',
            mask: true
          });
        }else{
          wx.showModal({
            title: '警告',
            content: '服务器错误',
            showCancel:false
          })
        }
      }
    })
  }
  ,
  bindTextAreaBlur: function(e) {
    console.log(e.detail.value)
    var questionAdvice = e.detail.value;
    this.setData({
      questionAdvice:questionAdvice
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.showModal({
      title: '提示',
      content: '不断提高教学质量，是您和我们共同的期盼。对任课教师的授课和课程进行客观、公正的评价，是提高教学质量的基础工作。因此，您的评价对提高学校教学质量和维护您自身的权益都将起到重要的作用。评教是不记名的，无须有任何顾虑，尽管放心。',
      showCancel:false
    })
  },
  question1:function (e) {
    this.setData({
      index1: e.detail.value
    })
  },
  question2:function (e) {
    this.setData({
      index2: e.detail.value
    })
  },
  question3:function (e) {
    this.setData({
      index3: e.detail.value
    })
  },
  question4:function (e) {
    this.setData({
      index4: e.detail.value
    })
  },
  question5:function (e) {
    this.setData({
      index5: e.detail.value
    })

  },
  question6:function (e) {
    this.setData({
      index6: e.detail.value
    })

  },
  question7:function (e) {
    this.setData({
      index7: e.detail.value
    })

  },
  question8:function (e) {
    this.setData({
      index8: e.detail.value
    })

  },
  question9:function (e) {
    this.setData({
      index9: e.detail.value
    })

  },
  question10:function (e) {
    this.setData({
      index10: e.detail.value
    })

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})